﻿#region << 文 件 说 明 >>

/*----------------------------------------------------------------
// 文件名称：BorderAddShadow
// 创 建 者：杨程
// 创建时间：2021/8/25 17:54:11
// 文件版本：V1.0.0
// ===============================================================
// 功能描述：
//
//
//----------------------------------------------------------------*/

#endregion

namespace Vampirewal.Core.WPF.Theme;

/// <summary>
/// 给Border添加阴影的附加属性
/// </summary>
public class BorderAddShadow : DependencyObject
{
    public static bool GetIsShowShadow(DependencyObject obj)
    {
        return (bool)obj.GetValue(IsShowShadowProperty);
    }

    public static void SetIsShowShadow(DependencyObject obj, bool value)
    {
        obj.SetValue(IsShowShadowProperty, value);
    }

    // Using a DependencyProperty as the backing store for IsShowShadow.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty IsShowShadowProperty =
        DependencyProperty.RegisterAttached("IsShowShadow", typeof(bool), typeof(BorderAddShadow), new PropertyMetadata(false, OnIsShowShadowChanged));

    private static void OnIsShowShadowChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
    {
        var border = obj as Border;
        if (border != null)
        {
            DropShadowEffect drop = new DropShadowEffect()
            {
                BlurRadius = 5,
                Direction = 0,
                Opacity = 0.7,
                ShadowDepth = 0,
                Color = (Color)ColorConverter.ConvertFromString("#FF5864")
            };

            border.Effect = drop;
        }
    }
}